package com.hibernate.domain;

import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.type.Type;

public class CompositeUserType implements
		org.hibernate.usertype.CompositeUserType {
	private String[] propertyNames = { "streetAddress", "city", "state",
			"zipCode"

	};
	private Type[] propertyTypes = { Hibernate.STRING, Hibernate.STRING,
			Hibernate.STRING, Hibernate.STRING };

	@Override
	public Object assemble(Serializable cached, SessionImplementor session,
			Object owner) throws HibernateException {
	
		return deepCopy(cached);
	}

	@Override
	public Object deepCopy(Object value) throws HibernateException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Serializable disassemble(Object value, SessionImplementor session)
			throws HibernateException {
	
		return (Serializable) deepCopy(value);
	}

	@Override
	public boolean equals(Object x, Object y) throws HibernateException {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public String[] getPropertyNames() {

		return propertyNames;
	}

	@Override
	public Type[] getPropertyTypes() {
		return propertyTypes;
	}

	@Override
	public Object getPropertyValue(Object component, int property)
			throws HibernateException {
		Address addr = (Address) component;
		switch (property) {
		case 0:
			return addr.getStreetAddress();
		case 1:
			return addr.getState();
		case 2:
			return addr.getCity();
		case 3:
			return addr.getZipcode();

		}
		throw new IllegalArgumentException(property
				+ "is an invalid property index for class type"
				+ component.getClass().getName());

	}

	@Override
	public int hashCode(Object x) throws HibernateException {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public boolean isMutable() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Object nullSafeGet(ResultSet rs, String[] names,
			SessionImplementor session, Object owner)
			throws HibernateException, SQLException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void nullSafeSet(PreparedStatement st, Object value, int index,
			SessionImplementor session) throws HibernateException, SQLException {
		// TODO Auto-generated method stub

	}

	@Override
	public Object replace(Object original, Object target,
			SessionImplementor session, Object owner) throws HibernateException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Class returnedClass() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setPropertyValue(Object component, int property, Object value)
			throws HibernateException {
		Address addr = (Address) component;
		String propertyValue = (String) value;
		switch (property) {
		case 0:
			addr.setStreetAddress(propertyValue);
			return;
		case 1:
			addr.setState(propertyValue);
			return;
		case 2:
			addr.setCity(propertyValue);
			return;
		case 3:
			addr.setZipcode(propertyValue);
			return;

		}
	}

}
